import modelExtend from 'dva-model-extend'
import { model } from '@/common/model/BaseModel'
import { getPropView, getPtypeView, getRepairView } from '../services/dashboard'

export default modelExtend(model, {
  namespace: 'dashboard',
  state: {
    propViewData: {},
    ptypeViewData: [],
    repairViewData: [],
  },
  effects: {
    *fetchPropView(_, { call, put }) {
      // 查询数据
      const res = yield call(getPropView)
      if (res && res.success) {
        yield put({
          type: 'updateState',
          payload: {
            propViewData: res.data || {},
          },
        })
      }
    },

    *fetchPtypeView({ payload }, { call, put }) {
      const res = yield call(getPtypeView, payload)
      if (res && res.success) {
        yield put({
          type: 'updateState',
          payload: {
            ptypeViewData: res.data || [],
          },
        })
      }
    },

    *fetchRepairView({ payload }, { call, put }) {
      const res = yield call(getRepairView, payload)
      if (res && res.success) {
        yield put({
          type: 'updateState',
          payload: {
            repairViewData: res.data || [],
          },
        })
      }
    },
  },
})
